package com.morgankelly.action;

import java.util.ArrayList;
import java.util.List;

import com.morgankelly.po.Account;
import com.morgankelly.po.Blog;
import com.morgankelly.po.BlogComment;
import com.morgankelly.vo.BlogCommentVO;

@SuppressWarnings("serial")
public class BlogCommentAction extends BaseAction {
    
	public String input() {

		setBlogCommentVOList(initBlogCommentVO());
		
		setAccountList(getAuthService().getAccountList());
		setBlogList(getBlogService().getBlogList());
		initSideBar();
		return INPUT;
	}
	
	public String add() {

		BlogComment blogComment = new BlogComment();
		
		blogComment.setContent(content);
		blogComment.setAccountID(accountID);
		blogComment.setBlogID(blogID);

		setBlogCommentVOList(initBlogCommentVO());
		setAccountList(getAuthService().getAccountList());
		setBlogList(getBlogService().getBlogList());
		initSideBar();
		return ADD;
	}
	

	private Long accountID;
    private Long blogID;
    private String content;
	public Long getAccountID() {
		return accountID;
	}

	public void setAccountID(Long accountID) {
		this.accountID = accountID;
	}

	public Long getBlogID() {
		return blogID;
	}

	public void setBlogID(Long blogID) {
		this.blogID = blogID;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	private List<BlogCommentVO> initBlogCommentVO() {
		List<BlogCommentVO> blogCommentVOList = new ArrayList<BlogCommentVO>();
		List<BlogComment> blogCommentList = getBlogService().getBlogCommentList();
		
		BlogCommentVO blogCommentVO;
		
		for (BlogComment blogComment : blogCommentList) {
			blogCommentVO = new BlogCommentVO();
			
			blogCommentVO.setContent(blogComment.getContent());
			blogCommentVO.setCreateTime(blogComment.getCreateTime());

			Account account = getAuthService().getAccountByID(blogComment.getAccountKey().getId());
			blogCommentVO.setAccountDisplayName(account.getDisplayName());
			
			Blog blog = getBlogService().getBlogByID(blogComment.getBlogKey().getId());
			blogCommentVO.setBlogTitle(blog.getTitle());
		    
			blogCommentVOList.add(blogCommentVO);
		}
		
		return blogCommentVOList;
	}
	
}
